import { defineStore } from "pinia"

//选项式API写法
//defineStore函数创建pinia小模块，参数("名称",{配置})
let useInfoStore = defineStore("info", {
  //状态值
  state: () => {
    return {
      count: 99,
      arr: [1, 2, 3, 4, 5]
    }
  },
  // 异步方法
  actions: {
    changeCount() {
      this.count++
    }
  },
  // 计算属性
  getters: {
    total() {
      let res: number = this.arr.reduce((pre: number, cur: number) => {
        return pre + cur
      }, 0)
      return res
    }
  }
})
export default useInfoStore